package com.ywj.boot_security.config;

import com.ywj.boot_security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserService userService;

    @Bean
    public PasswordEncoder passwordEncoder(){
        //提供加密方式
        return new BCryptPasswordEncoder();
    }

    //配置登陆验证方式
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //指定登陆用我们自己的方法
        auth.userDetailsService(userService)
                .passwordEncoder(passwordEncoder());
    }


}

